<link rel="stylesheet" type="text/css" href="{:CSS}datetimepicker.min.css">
<div class="row"><h3 class="page-header">留言管理</h3></div>
<div class="row">
    <div class="panel panel-default">
    
        <div class="panel-body">
        
        <form action='{:U("Message/index")}' class="form-inline text-right m-b-5 fr">
                关键字：<input type="text" name='keyWord' value='{$Think.get.keyWord}' class="form-control">
                  时间：<input class="form-control datepick required" name="start_time" value="{$Think.get.start_time}" size="10" placeholder="起始时间" readonly>
                <input class="form-control datepick required" name="end_time" value="{$Think.get.end_time}" size="10" placeholder="终止时间" readonly>
                    
                分类：<select name='cid' class="form-control mr20 w150">
                    <option value='-1'>全部</option>
                     <volist name="classifyList" id="classifyList">
                        <option value='{$classifyList.id}' <eq name='Think.get.cid' value="$classifyList.id">selected</eq>>{$classifyList.name}</option>
                    </volist>
                </select>
                
                <button class="btn btn-primary" type="submit">搜索</button>
            </form>
        	<div class="table-responsive">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th width="60">序号</th>
                            <th>姓名</th>
                            <th>联系方式</th>
                            <th>留言内容</th>
                            <th>回复内容</th>
                            <th>提交时间</th>
                            <th width="164px">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                     <empty name="list">
                            <tr><td colspan="7" align="center">暂无信息</td></tr>
                        </empty>
                        <volist name="list" id="list">
                            <tr>
                                <td>{$i}</td>
                                <td>{$list.name}</td>
                                <td>{$list.phone}</td>
                                <td>{$list.msg}</td>
                                <td>{$list.reply}</td>
                                <td>{$list.times|date='Y-m-d H:i', ###}</td>       
                                <td>
                                    <button class="btn-sm btn btn-default replyText" data-id='{$list.id}'>回复</button>
                                   <button data-url='{:U("Message/del?id=".$list["id"])}' class="btn-sm btn btn-default delBtn" type="button">删除</button>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
            </div>
            {$page}
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="" role="form" id="myform" method="post" class="form-horizontal" data-callback="_form_defult_callback()">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h4 class="modal-title">分类管理</h4>
                </div>
                
                <div class="form-group">
                    <label class="col-sm-3 control-label">姓名：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="name" readonly="readonly">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">联系方式：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control required" name="phone" readonly="readonly">       
                    </div>
                </div>
               <div class="form-group">
                    <label class="col-sm-3 control-label">分类：<span class="c-red">*</span></label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control" name="c_name" readonly="readonly"> 
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">留言内容：</label>
                    <div class="col-sm-4 input-group">
                        <textarea class="form-control" name="msg" readonly="readonly"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">提交时间：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control " name="times" readonly="readonly">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">回复内容：</label>
                    <div class="col-sm-4 input-group">
                        <textarea class="form-control" name="reply"></textarea>
                    </div>
                </div>
                 <div class="form-group">
                    <label class="col-sm-3 control-label">回复时间：</label>
                    <div class="col-sm-4 input-group">
                        <input class="form-control datepick required" name="reply_times" readonly="readonly">
                    </div>
                </div>
                
                
                <div class="modal-footer">
                    <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                    <button class="btn btn-primary" type="submit">保存</button>
                </div>
                <input type='hidden' name='id'>
            </form>
        </div>
    </div>
</div>

<div id="myModal" class="modal fade in" style="display: none;">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">查看/回复留言</h4>
            </div>
            <div class="modal-body" style="padding-top: 0px;">加载中 。。。</div>
            <div class="modal-footer">
                <button data-dismiss="modal" class=" btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary submitReplay" type="button">回复</button>
            </div>
        </div>
    </div>
</div>
<input id="id" type="hidden" name="id">
<script type="text/javascript" src="{:JS}daterangepicker.min.js"></script>
<script type="text/javascript">

$(function(){
    $('.addClassify').click(function(){
        $('#myform')[0].reset();
        $('#myModal').modal('show');
    });
    $('.replyText').click(function(){
        $('#myform')[0].reset();
        var id = $(this).data('id'); 
        waiting();
        $.get('{:U("Message/getMsgInfo")}', {id: id}, function(data){
            complete();
            if(data.status == 1){
                var _get_info = data.info;
                $('#myform input[name="id"]').val(_get_info.id);
                $('#myform input[name="c_name"]').val(_get_info.c_name);

                $('#myform input[name="name"]').val(_get_info.name);
                $('#myform input[name="phone"]').val(_get_info.phone);
                $('#myform input[name="email"]').val(_get_info.email);
                $('#myform textarea[name="msg"]').val(_get_info.msg);
                $('#myform input[name="times"]').val(_get_info.times);
                $('#myform textarea[name="reply"]').val(_get_info.reply);
                $('#myform input[name="reply_times"]').val(_get_info.reply_times);
                $('#myform').attr('action', '{:U("Message/reply")}');
                $('#myModal').modal('show');
            }else{
                showInfo(data.info);
                setTimeout('_form_defult_callback()', 1600);
            }
        });
    });
});

//提交回复信息
$('.submitReplay').click(function(){
    var id = $('#id').val(), content = $('#reply').val();
    if(!content){
        showInfo('请输入回复内容');
    }else{
        waiting();
        $.post('{:U("Message/reply")}', {id: id, reply: content}, function(data){
            complete(); showInfo(data.info);
            if (data.status == 1) {
                $('#myModal').modal('hide');
            };
        });
        
    }
});

</script>